<script setup lang='ts'>
import { onMounted, ref, watch } from "vue"
import { showFailToast, showToast } from 'vant';
import { useRouter } from "vue-router";
import { useCounterStore } from "@/stores/counter";
const store = useCounterStore()
const $router = useRouter()

const checked = ref<any>(localStorage.getItem('read-mode') || false)
const userInfo = ref<any>(null)
onMounted(() => {
    if (localStorage.getItem('userInfo')) {
        userInfo.value = JSON.parse(`${localStorage.getItem('userInfo')}`)
    }
    if (localStorage.getItem('read-mode') == 'true') {
        checked.value = true
    } else {
        checked.value = false
    }
})
watch(checked, (checked, prev) => {
    localStorage.setItem('read-mode', `${checked}`)

})

const toBuyOrUpload = () => {
    // if (store.userInfo) {
    //     $router.push('/buy-upload')
    // } else {
    //     showFailToast('请登录！')
    // }
    $router.push('/buy-upload')
}
</script>

<template>
    <!-- <div class="my" :class="{ 'night-mode': checked }"> -->
    <div class="my">
        <div class="my-letter">
            <img src="@/assets/imgs/信息1.png" alt="">
        </div>
        <div class="my-info">
            <div class="logo">
                <img src="@/assets/imgs/书籍1.png" alt="" v-if="!userInfo">
                <img :src="userInfo.avatar" alt="" v-else>
            </div>
            <p @click="$router.push('/login')" v-if="!userInfo">点击登录</p>
            <p v-else @click="$router.push('/userInfo')">{{ userInfo.nickName }}</p>
        </div>
        <div class="my-coin">
            <div class="balance">
                <span>余额</span>
                <span>充值送红包</span>
                <van-button type="danger" round size="small" @click="showToast('没有充值');">充值</van-button>
            </div>

            <div class="sign-in">
                <span>签到</span>
                <span>做任务领红包</span>
                <van-button round size="small" color="#fc1c1c" plain @click="showToast('没有签到');">签到</van-button>
            </div>
        </div>
        <ul class="my-list">
            <li @click="showToast('没有笔记');">
                <div class="left">
                    <img src="@/assets/imgs/笔记1.png" alt="">
                    <span>笔记</span>
                </div>
                <div class="right">
                    <img src="@/assets/imgs/右边1.png" alt="">
                </div>
            </li>
            <li @click="toBuyOrUpload">
                <div class="left">
                    <img src="@/assets/imgs/上传.png" alt="">
                    <span>已购和上传</span>
                </div>
                <div class="right">
                    <img src="@/assets/imgs/右边1.png" alt="">
                </div>
            </li>
            <li>
                <div class="left">
                    <img src="@/assets/imgs/客服1.png" alt="">
                    <span>在线客服</span>
                </div>
                <div class="right">
                    <img src="@/assets/imgs/右边1.png" alt="">
                </div>
            </li>
            <li>
                <div class="left">
                    <img src="@/assets/imgs/月亮1.png" alt="">
                    <span>夜间模式</span>
                </div>
                <div class="right">
                    <van-switch v-model="checked" size="22px" active-color="#ee0a24" inactive-color="#dcdee0" />
                </div>
            </li>
            <li>
                <div class="left">
                    <img src="@/assets/imgs/积分1.png" alt="">
                    <span>积分商城</span>
                </div>
                <div class="right">
                    <img src="@/assets/imgs/右边1.png" alt="">
                </div>
            </li>
            <li>
                <div class="left">
                    <img src="@/assets/imgs/设置2.png" alt="">
                    <span>设置</span>
                </div>
                <div class="right">
                    <img src="@/assets/imgs/右边1.png" alt="">
                </div>
            </li>
        </ul>
    </div>
</template>

<style lang="less" >
.my {
    width: 100vw;
    height: 100%;
    padding: 20rem;

    &.night-mode {
        background-color: #333;

        span {
            color: rgb(228, 221, 221);
        }

        >.my-info {
            p {
                color: rgb(228, 221, 221);
            }
        }

        >.my-coin {
            border-bottom: 1px solid #666;

            .balance,
            .sign-in {
                span {
                    color: rgb(228, 221, 221);

                    &:nth-child(1) {
                        color: rgb(228, 221, 221);
                    }
                }
            }

            .sign-in {
                span {
                    .van-button__text {
                        color: #888;
                    }
                }
            }
        }

    }

    >.my-letter {
        width: 100%;
        // display: flex;
        // justify-content: right;
        text-align: right;

        img {
            width: 28rem;
            display: inline;
        }
    }

    >.my-info {
        display: flex;
        justify-content: left;
        align-items: center;

        .logo {
            width: 70rem;
            height: 70rem;
            background-color: #eee;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 20rem;

            img {
                width: 50rem;
                height: 50rem;
                border-radius: 50%;
            }
        }

        p {
            color: #333;
            font-size: 24rem;
        }
    }

    >.my-coin {
        display: flex;
        justify-content: space-around;
        margin-top: 30rem;
        padding-bottom: 20rem;
        border-bottom: 1px solid #eee;

        .balance,
        .sign-in {
            display: flex;
            flex-direction: column;
            align-items: center;

            >span {

                font-size: 13rem;
                color: #2d2d2d;

                &:nth-child(1) {
                    color: #333;
                    font-size: 16rem;
                    font-weight: bold;
                }

                &:nth-child(2) {
                    margin: 10rem 0;

                }
            }

            .van-button__text {
                font-weight: normal;
                padding: 0 20rem;
                color: #fff;
            }
        }

        .sign-in {
            .van-button__text {
                color: #fc1c1c;
            }
        }
    }

    >ul.my-list {
        padding-top: 25rem;

        li {
            display: flex;
            justify-content: space-between;
            margin-bottom: 40rem;

            img {
                width: 25rem;
            }

            .left {
                display: flex;
                align-items: center;

                span {
                    font-size: 14rem;
                    // color: #888;
                    margin-left: 15rem;
                }
            }

            .right {}
        }
    }

}
</style>
